package main

import (
	"fmt"
)

type LinkedList struct {
	head Node
}

type Node struct {
	num  int
	data interface{}
	next *Node // 这里和java不一样,需要定义的是引用
}

// 初始化链表-> 头结点
func NewLinkedList() *LinkedList {
	return &LinkedList{
		head: Node{
			num:  0,
			data: "0",
			next: nil,
		}}
}

// 尾插
func (list *LinkedList) addNode(head *Node) {
	temp := head
	for {
		if temp.next == nil {
			break
		}
		temp = temp.next
	}
	temp.next = head

}

func (list *LinkedList) isEmpty() bool {
	if list.head.next == nil {
		fmt.Println("this linkedList is nil")
	}
	fmt.Println("this linkedList is not nil")
	return false
}

func (list *LinkedList) show() {
	b := list.isEmpty()
	temp := list.head.next
	for b {
		if temp == nil {
			break
		}
		fmt.Println(temp)
		temp = temp.next
	}
}

func main() {

	node := &Node{num: 1, data: "老王"}
	node1 := &Node{num: 1, data: "老李"}
	node2 := &Node{num: 1, data: "老大"}
	node3 := &Node{num: 1, data: "老2"}

	list := NewLinkedList()
	list.addNode(node)
	list.addNode(node1)
	list.addNode(node2)
	list.addNode(node3)
	list.isEmpty()
	list.show()

}
